home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / resource.arc / RES86A.ASM < prev    next >
Assembly Source File  |  1985-08-02  |  44KB  |  2,367 lines

  1.     title    'RES86 DISASSEMBLER'
  2.     page    60,132
  3. ;
  4. ;    last edit 02/10/85 wde
  5. ;    2/10/85 2.3b fix goof in read .ctl funct
  6. ;    fix flow indic semic test,repair 8080 sym lookup
  7. ;    fix sym type write bug
  8. ;    1/17 2.3a add fixes from b kendall
  9.  
  10. ;    3/21/85 3.0 convert to masm format for ms-dos systems by Craig Derouen
  11.  
  12.  
  13. code    segment byte public
  14.  
  15.     extrn    cntenb:byte,opdtyp:byte,quiflg:byte,segflg:byte,segmsk:byte
  16.     extrn    segsho:byte,sdflg:byte,trmflg:byte,typndx:byte,wfiflg:byte
  17.     extrn    wrtflg:byte,xcsw:byte,adb:byte,strcnt:byte,symtyp:byte
  18.  
  19.     extrn    ascbld:word,cofset:word,ctlbas:word,ctltop:word,curofs:word
  20.     extrn    curpar:word,dmpcnt:word,dmpend:word,dmpstt:word,docend:word
  21.     extrn    doctbl:word,ecnt:word,fndadd:word,fndpc:word,hiload:word
  22.     extrn    insloc:word,lastwd:word,liscnt:word,mcbsiz:word,ofsptr:word
  23.     extrn    nrsegs:word,nxtctl:word,pcntr:word,rplptr:word,segsiz:word
  24.     extrn    stack:word,symtp:word,xcptr:word,cmdbuf:word
  25.     extrn    segnam:word,mcbbas:word,fake_comtbl:word
  26.  
  27.     extrn    addfn:near,bdos:near,cmentr:near,cmkill:near
  28.     extrn    creatf:near,cstbl:near,crlf:near,dline:near
  29.     extrn    dcrlf:near,fclose:near,fopen:near,gtcmd:near,gtval:near
  30.     extrn    hexl:near,hexr:near,ifasci:near,initbl:near
  31.     extrn    keychk:near,lita86:near,litall:near,litcmd:near,litctl:near
  32.     extrn    litdoc:near,litsym:near,lngth:near,locsym:near,prntde:near
  33.     extrn    prtstr:near,prspc:near,prword:near,pstar:near,pstrg:near
  34.     extrn    rdfchr:near,semic:near,symbas:near,symluk:near
  35.     extrn    tabc:near,typech:near,wtfchr:near,xo:near,xo0:near,flushf:near
  36.     extrn    cmpstr:near,pstg:near
  37.  
  38.     public    start,hsym,nwln0,delim,cmerr,nxcmd
  39.  
  40.     public    fcb,tbuf
  41.  
  42. ; dummy publics for symbol file
  43.  
  44.     public    entry,ardnam,restrt,l01cf,funlp,fndfun,segonl,fcttbl,fctend
  45.     public    deliok,cmhelp,cmtrim,trmof,cmpurg,l02c9,cmprlg,l02df,pfnlp
  46.     public    nofnam,pnmdun,l031d,prlglp,l032c,l033d,l034b,l0362,l0380,l0394
  47.     public    nodisp,sgreqs,updseg,segmch,segmtb,cmqiet,l03b2,cmdump,l0411
  48.     public    l0418,dump0,dump1,dump3,dmphdr,cntdmp,dump4,dmpln,wdspc1
  49.     public    wdspc2,wdspc3,dmpasc,period,chrctr,wdspc4,lcmplt,sducnt,l04e8
  50.     public    l04ef,dusymt,frmbgn,frmsym,agnsym,l051a,spit,spit1,spitcr,spcrlf
  51.     public    spcry,iecnt,prntos,gfnam,l056a,l057d,nodriv,mvnfld
  52.     public    eatfld,l05b6,padfld,cmatmt,cmbld,cmlist,list1,list2,list3
  53.     public    tenl,contl,flagck,builda,loop8,follow,morel,nwln,ncsemi,cntcmt
  54.     public    ntbksl,morel1,morel2,ncmt,cml15,l06fd,ckbmd,ckhmd,ckwmd,badmd,ictl
  55.     public    slicnt,l0762,l0776,l077d,dsmode,wmode,stpln,hmode,bmode,bmode1
  56.     public    nprtc,morinv,ltlf,mvup,trysym,nstpln,l0864,nxinv,conasc,morasc
  57.     public    l08ac,yet,still,lastqt,fnlqt,qtb,cmstts,nodoct,l0984,sgplp
  58.     public    usdseg,sgpen,prwval,cmfind,l09c6,l09d1,prevf,nyet
  59.     public    cmeof,l0a35,cmread,rdaprv,wntall,lodall,chgtyp,ntlall,symffd
  60.     public    l0a8a,wntcmd,lodcmd,cmdlds,modofs,cmhlp,cmhmlp,set_dmablk
  61.     public    mrqok,l0ac4,l0adc,l0aec,doclod,gotdoc,lodsym,comrd_lp
  62.     public    ldsym2,loddoc,lddoc2,ldasfl,skppre,l0b6c,drdsk1,lpasld,ldassp
  63.     public    hexbin,l0ba3,l0ba8,l0baf,l0bb5,erstbl,etlp1,etlp2,cmsave
  64.     public    savok,allsav,nosdoc,nossym,havctl,ntsall,ntssym,ntsctl,symsav
  65.     public    l0bf4,l0bf7,sdskp1,l0c0c,oufend,ntsdoc,outadr,sava86,savdoc
  66.     public    rrqerr,l0d20,cmctl,l0d45,l0d4f,l0d5a,enterc,entrc2,entrc4
  67.     public    l0d84,l0dba,l0dc6,cltrck,ctlck2,cltrrt,l0bf5,entrc5,entrc7
  68.     public    entrc8,l0e34,ctlook,ctlk2,l0e4s,l0e5c,l0e48,ctlk4,l0e65,clist0
  69.     public    clist,clist2,l0e87,l0e99,skclis,savctl,svctl0,l0ebf,l0ee6
  70.     public    lodctl,ctlfnd,l0ef7,l0efd,l0f0b,l0f23,l0f30,cmcmnt,cmnt0,cmnt2
  71.     public    cmnt1,l0f52,l0f5d,l0f71,l0f7d,comchk,l0fa6,l0fb2,l0fc3,l0fce
  72.     public    l0fd4,l0fd8,l0fec,l0ffa,l100b,l1015,l1023,l1041,l104c,cmusec
  73.     public    l10ce,ustok,uaset,l10ef,l111c,l1151,l1152,good_vers,good_mem
  74.  
  75.     assume cs:code,ds:code
  76.  
  77.     org    5ch
  78. fcb    db    36 dup (?)
  79. tbuf    db    128 dup(?)    ;that takes care of the first page
  80.  
  81.  
  82. symmax    equ    9        ;max chars in symbol
  83. tab    equ    9
  84. cr    equ    0dh
  85. lf    equ    0ah
  86. initlcnt equ    20
  87.  
  88. ;
  89.     org    100h
  90.  
  91.     if2
  92.     %out    Compiling in PASS 2 finally!
  93.     endif
  94.  
  95. start:
  96.     mov    ah,30h
  97.     int    21h
  98.     cmp    al,2
  99.     jae    good_vers
  100.     mov    dx,offset bad_vers
  101.     mov    ah,9
  102.     int    21h
  103.     int    20h            ; back to DOS!
  104.  
  105. bad_vers db    cr,lf,7,'Wrong version of DOS! Must be 2.0 or higher$'
  106.  
  107. good_vers:
  108. ; First thing is to de-allocate memory so we can grab portions at a time.
  109.     mov    bx,offset symbas    ; the end of program
  110.     sub    bx,100h            ; start of program
  111.     mov    cl,4
  112.     shr    bx,cl            ; convert to paras!
  113.  
  114. ; Now add about 10k for symbol table
  115.     add    bx,640            ; 10K in paras
  116.     mov    ah,4ah
  117. ;    int    21h            ; here we go!
  118. ;    jnc    good_mem        ; we have enough!
  119. ;    mov    ah,9
  120. ;    mov    dx,offset memory_fail
  121. ;    int    21h
  122. ;    mov    ax,4cffh
  123. ;    int    21h            ; exit with a -1
  124. ;
  125. ;memory_fail db    cr,lf,7,'Not enough memory to run!$'
  126.  
  127. good_mem:
  128.  
  129.     call    entry
  130.     db    'RESOURCE by Ward Christensen',cr,lf
  131.     db    'Transl. to 8086 by Larry Etienne',cr,lf
  132.     db    'Converted 8086 MS-DOS Ver. 3.0',cr,lf
  133.     db    'by C.Derouen (3-26-85)',cr,lf
  134.     db    'Copyright 1980$'
  135. ;
  136. entry:    pop    dx
  137.     mov    ax,ds
  138.     cli
  139.     mov    ss,ax
  140.     mov    sp,offset stack
  141.     sti
  142.     mov    es,ax            ;start = data seg
  143.     push    cs
  144.     pop    ds            ;segment for signon msg
  145.     mov    ah,9
  146.     call    bdos
  147.     mov    ax,ss
  148.     mov    ds,ax            ;restore normal
  149.     call    initbl
  150.     mov    al,fcb+1
  151.     cmp    al,' '+1
  152.     jb    restrt
  153.     call    prtstr
  154.     db    cr,lf,'Reading All Files for ',0
  155.     mov    bx,offset fcb+1
  156.     mov    ch,8
  157. ardnam:    mov    al,[bx]
  158.     call    typech
  159.     inc    bx
  160.     dec    ch
  161.     jnz    ardnam
  162.     call    lodall
  163.     call    prtstr
  164.     db    cr,lf,'Read Complete',cr,lf,0
  165.     jmp    short fstcmd
  166. ;
  167. restrt:    call    initbl
  168. fstcmd:    call    prtstr
  169.     db    cr,lf,'Type H for Help, ? for Stats',cr,lf,0
  170. ;
  171. nxcmd:    xor    al,al
  172.     mov    wfiflg,al
  173.     mov    quiflg,al        ;not quiet, no output
  174.     mov    segflg,al        ;clear segment use
  175.     mov    sp,offset stack
  176.     call    gtcmd
  177. l01cf:    mov    bx,offset cmdbuf+2    ;first chars of command
  178.     cmp    word ptr 1[bx],':S'
  179.     jz    segonl            ;just change segment
  180.     mov    al,[bx]            ;get the char
  181.     mov    bx,offset fcttbl
  182.     mov    ch,(offset fctend-offset fcttbl)/3    ;tbl entries
  183. funlp:    cmp    al,cs:[bx]        ;test char match
  184.     jz    fndfun
  185.     inc    bx
  186.     inc    bx
  187.     inc    bx
  188.     dec    ch
  189.     jnz    funlp
  190.     jmp    cmerr
  191. ;
  192. fndfun:    inc    bx
  193.     mov    dx,cs:[bx]        ;address of function
  194.     jmp    dx
  195. ;
  196. segonl:    inc    bx    ;pre-adj
  197.     call    updseg
  198.     jmp    short nxcmd
  199. ;
  200. fcttbl    db    cr
  201.     dw    offset nxcmd
  202.     db    ';'
  203.     dw    offset cmcmnt
  204.     db    'A'
  205.     dw    offset cmatmt
  206.     db    'B'
  207.     dw    offset cmbld
  208.     db    'C'
  209.     dw    offset cmctl
  210.     db    'D'
  211.     dw    offset cmdump
  212.     db    'E'
  213.     dw    offset cmentr
  214.     db    'F'
  215.     dw    offset cmfind
  216.     db    'G'
  217.     dw    offset cmexit
  218.     db    'H'
  219.     dw    offset cmhelp
  220.     db    'K'
  221.     dw    offset cmkill
  222.     db    'L'
  223.     dw    offset cmlist
  224. ;    db    'O'
  225. ;    dw    offset cmofst
  226.     db    'P'
  227.     dw    offset cmprlg
  228.     db    'Q'
  229.     dw    offset cmqiet
  230.     db    'R'
  231.     dw    offset cmread
  232.     db    'S'
  233.     dw    offset cmsave
  234.     db    'T'
  235.     dw    offset cmtrim
  236.     db    'U'
  237.     dw    offset cmusec
  238.     db    'X'
  239.     dw    offset cmpurg
  240.     db    'Z'
  241.     dw    offset cmeof
  242.     db    '?'
  243.     dw    offset cmstts
  244. fctend    db    0
  245. ;
  246. cmerr:    xor    al,al
  247.     mov    wfiflg,al
  248.     mov    quiflg,al        ;clear output and silent flags
  249.     pop    bx            ;addr called from
  250.     push    bx            ;in case stack empty 
  251.     call    prword            ;show where for debugging
  252.     call    prtstr
  253.     db    '? Cmd. Error',7,cr,lf,0
  254.     jmp    nxcmd
  255. ;
  256. delim:    cmp    al,' '
  257.     jz    deliok
  258.     cmp    al,','
  259.     jz    deliok
  260.     call    cmerr    ;expected delimiter missing
  261. deliok:    ret
  262.  
  263. ; Exit resource here
  264. cmexit:
  265.     mov    ax,4c00h    ; say no errors
  266.     int    21h
  267.  
  268. ;
  269. ;    help function
  270. ;
  271. cmhelp:    
  272. ; Test to see if extended help is needed.
  273.     mov    al,byte ptr cmdbuf+3
  274.     cmp    al,cr        ; nothing there?
  275.     je    full_help
  276.     cmp    al,'X'        ; help extended key
  277.     jne    full_help
  278.     jmp    extnd_help    ; show extended help
  279. full_help:
  280.     call    prtstr            ;lots to put out here!
  281. ;line  1
  282.     db    cr,lf,'             HELP ON RES86 -- COMMAND SUMMARY'
  283. ;line  2
  284.     db    cr,lf,';ADDR,@COMMENT    ENTER COMMENT AT ADDR    '
  285.     db    ' @={;|*|\|} \=NL, ;=APPND, *=REPL INST'
  286. ;line  3
  287.     db    cr,lf,';        LIST COMMENTS TABLE    '
  288.     db    ';ADDR,        DELETE COMMENT'
  289. ;line  4
  290.     db    cr,lf,"A (SEE L)    ATTEMPT TO FIND DB'",'S    '
  291.     db    'B (SEE L)    BUILD SYMBOL TABLE'
  292. ;line  5
  293.     db    cr,lf,'C        DUMP CONTROL TABLE    '
  294.     db    'CNNNN        DUMP CTRL TABLE AT NNNN'
  295. ;line  6
  296.     db    cr,lf,'CNNNN,X         SET CTRL (X=BEHISW)    '
  297.     db    'DNNNN        DUMP FROM NNNN ON'
  298. ;line  7
  299.     db    cr,lf,'DAAAA,BBBB    DUMP OVER RANGE        '
  300.     db    'D,BBBB        DUMP THRU BBBB'
  301. ;line  8
  302.     db    cr,lf,'D        DUMP A PAGE MORE    '
  303.     db    'D=NN        SET DUMP SIZE DEFAULT'
  304. ;line  9
  305.     db    cr,lf,'DS        DUMP THE SYMBOL TABLE    '
  306.     db    'DS.SYMBOL    DUMP STARTING AT SYMBOL'
  307. ;line 10
  308.     db    cr,lf,'ENNNN,.SYM[,M] ENTER SYMBOL INTO TABLE    '
  309.     db    'FNNNN,SSSS    FIND NNNN AFTER SSSS'
  310. ;line 11
  311.     db    cr,lf,'F OR FNNNN    CONT FIND OR FIND NNNN    '
  312.     db    'SEG PFX OK ON CMDS A,B,C,D,F,L,O,;'
  313. ;    db    'ISSSS,OOOO    INC ADDRS>=SSSS BY OOOO'
  314. ;line 12
  315.     db    cr,lf,'K.SYMBOL    KILL SYMBOL FROM TABLE    '
  316.     db    'L        LIST NEXT '
  317.     db    (initlcnt/10)+'0',(initlcnt mod 10)+'0'
  318.     db    ' LINES'
  319. ;line 13
  320.     db    cr,lf,'LSSSS,EEEE    LIST OVER RANGE        '
  321.     db    'L,EEEE        LIST TO EEEE'
  322. ;line 14
  323.     db    cr,lf,'LSSSS        LIST '
  324.     db    (initlcnt/10)+'0',(initlcnt mod 10)+'0'
  325.     db    ' LINES FROM SSSS    '
  326.     db    'L=NN[,OTHERS]    SET LIST DEFAULT'
  327. ;line 15
  328. ;    db    cr,lf,'O        PRINT CURRENT OFFSET    '
  329. ;    db    'ONNNN        SET NEW OFFSET'
  330. ;line 16
  331.     db    cr,lf,'PSSSS,EEEE    GENERATE PROGRAM PROLOG    '
  332.     db    'Q        QUIET PREFIX'
  333. ;line 17
  334.     db    cr,lf,'RFILENAME.COM    READ FILE @ OFFSET         '
  335.     db    'RFILENAME.CTL    READ CONTROL TABLE'
  336. ;line 18
  337.     db    cr,lf,'RFILENAME.SMB    READ SYMBOL TABLE    '
  338.     db    'RFILENAME.DOC    READ COMMENTS TABLE'
  339. ;line 19
  340.     db    cr,lf,'RFILENAME.ALL    READ CTL, SMB, DOC, COM    '
  341.     db    'SFILENAME.ASM    SAVE ASM FILE'
  342. ;line 20
  343.     db    cr,lf,'SFILENAME.CTL    SAVE CTL FILE        '
  344.     db    'SFILENAME.SMB    SAVE SYM FILE'
  345. ;line 21
  346.     db    cr,lf,'SFILENAME.DOC    SAVE DOC FILE        '
  347.     db    'SFILENAME.ALL    CTL, SYM, DOC'
  348. ;line 22
  349.     db    cr,lf,'UNNNN        SET COMMENT TABLE ADDR    '
  350.     db    'X        RESTART RES86'
  351. ;line 23
  352.     db    cr,lf,'Z        WRITE EOF TO ASM FILE    '
  353.     db    '?        PRINT STATISTICS'
  354. ;line 24
  355.     db    cr,lf,0            ;finished!!
  356.     jmp    nxcmd
  357. extnd_help:
  358.     call    prtstr
  359.  
  360.     db    cr,lf,'Extended help for Resource-86'
  361.     db    cr,lf,'G    Exit back to MS-DOS'
  362.     db    cr,lf,'Segments may be overrriden with the SEGMENT override'
  363.     db    ' key such as DCS:0 for display code at Data Segment,offset 0'
  364.     db    cr,lf,0
  365.     jmp    nxcmd
  366. ;
  367. cmtrim:    mov    al,trmflg
  368.     not    al
  369.     mov    trmflg,al
  370.     or    al,al
  371.     jz    trmof
  372.     call    prtstr
  373.     db    'Trim On',cr,lf,0
  374.     jmp    nxcmd
  375. ;
  376. trmof:    call    prtstr
  377.     db    'Trim Off',cr,lf,0
  378.     jmp    nxcmd
  379. ;
  380. ;
  381. ;
  382. cmpurg:    call    prtstr
  383.     db    'Y/N purge all symbols & CTL?',0
  384.     call    gtcmd
  385.     mov    al,byte ptr cmdbuf+2
  386.     cmp    al,'Y'    ;59h
  387.     jnz    l02c9
  388.     call    erstbl    ;empty the segment tables
  389.     jmp    restrt
  390. ;
  391. l02c9:    cmp    al,'N'    ;4eh
  392.     jnz    cmpurg    ;bad answer
  393.     jmp    nxcmd
  394. ;
  395. ;
  396. ;
  397. cmprlg:    mov    bx,offset cmdbuf+3
  398.     mov    al,[bx]
  399.     cmp    al,cr
  400.     jnz    l02df
  401.     call    cmerr
  402. ;
  403. l02df:    call    gtval
  404.     call    delim
  405.     inc    bx
  406.     push    dx
  407.     push    bx
  408.     mov    wfiflg,1
  409.     call    pstg
  410.     db    9,'TITLE',9,27h,0
  411.     mov    bx,offset fcb+1
  412.     mov    al,[bx]
  413.     cmp    al,' '
  414.     jz    nofnam
  415.     mov    ch,8
  416. pfnlp:    mov    al,[bx]
  417.     call    typech
  418.     inc    bx
  419.     dec    ch
  420.     jnz    pfnlp
  421.     jmp    short pnmdun
  422. ;
  423. nofnam:    call    pstg
  424.     db    'DISASSEMBLY',0
  425. ;
  426. pnmdun:    call    pstg
  427.     db    27h,cr,lf,9,'ORG',9,0
  428.     pop    bx
  429.     pop    dx
  430.     mov    al,dh
  431.     call    xo0
  432.     mov    al,dl
  433.     call    xo
  434.     mov    al,'H'    ;48h
  435.     call    typech
  436.     call    crlf
  437.     push    dx
  438.     call    gtval
  439.     cmp    al,cr
  440.     jz    l031d
  441.     call    cmerr
  442. ;
  443. l031d:    pop    cx
  444.     mov    bx,offset symbas
  445. prlglp:    inc    bx
  446.     inc    bx
  447.     inc    bx
  448.     mov    al,[bx]
  449.     or    al,al
  450.     jnz    l032c            ;not table end
  451.     jmp    nxcmd
  452. ;
  453. l032c:    dec    bx
  454.     dec    bx
  455.     dec    bx
  456.     mov    ax,[bx]
  457.     sub    ax,cx
  458.     jb    l033d
  459.     mov    ax,[bx]
  460.     sub    ax,dx
  461.     jb    l0394
  462. l033d:    inc    bx
  463.     push    bx
  464.     push    cx
  465.     inc    bx
  466.     inc    bx
  467.     mov    ch,[bx]
  468.     push    bx
  469.     inc    bx
  470.     mov    al,[bx]
  471.     dec    bx
  472.     cmp    al,'A'    ;41h
  473.     jb    nodisp
  474. l034b:    inc    bx
  475.     mov    al,[bx]
  476.     cmp    al,'+'    ;2bh
  477.     jz    nodisp
  478.     cmp    al,'-'    ;2dh
  479.     jz    nodisp
  480.     dec    ch
  481.     jnz    l034b
  482.     pop    bx
  483.     mov    ch,[bx]
  484.     mov    wfiflg,1
  485. l0362:    inc    bx
  486.     mov    al,[bx]
  487.     call    typech
  488.     dec    ch
  489.     jnz    l0362
  490.     call    pstg
  491.     db    9,'EQU',9,'.',0
  492.     pop    cx
  493.     pop    bx
  494.     mov    al,[bx]
  495.     or    al,al
  496.     jz    l0380
  497.     call    xo0
  498. l0380:    dec    bx
  499.     mov    al,[bx]
  500.     call    xo
  501.     mov    al,'H'    ;48h
  502.     call    typech
  503.     call    crlf
  504.     mov    wfiflg,0
  505. l0394:    inc    bx
  506.     inc    bx
  507.     inc    bx
  508.     mov    al,[bx]
  509.     call    addfn
  510.     inc    bx
  511.     call    keychk
  512.     jmp    prlglp
  513. ;
  514. nodisp:    pop    bx
  515.     pop    cx
  516.     pop    bx
  517.     jmp    l0394
  518. ;
  519. sgreqs:    mov    bx,offset cmdbuf+4    ;process segment request
  520.     mov    ax,[bx]
  521.     cmp    ax,':S'            ; is xs: in place?
  522.     jz    updseg            ;yes, find which and set
  523.     ret                ;else do nothing
  524. updseg:    dec    bx
  525.     mov    al,[bx]    ;first seg char
  526.     sub    ah,ah            ;start at 0
  527.     cmp    al,'C'
  528.     jz    segmch
  529.     inc    ah
  530.     cmp    al,'D'
  531.     jz    segmch
  532.     inc    ah
  533.     cmp    al,'E'
  534.     jz    segmch
  535.     inc    ah
  536.     cmp    al,'S'
  537.     jz    segmch
  538.     ret                ;ignore any others
  539. ;
  540. segmch:    mov    segsho,al        ;for cmd. prompt display
  541.     mov    segflg,al        ;seg req given
  542.     mov    al,ah            ;count value
  543.     sub    ah,ah
  544.     mov    bx,ax            ;in a base reg
  545.     mov    cl,cs:byte ptr segmtb[bx]    ;get bit patt.
  546.     mov    opdtyp,cl        ;init symb select
  547.     mov    segmsk,cl        ;for testing symbols
  548.     mov    bl,12            ;size of segment record
  549.     mul    bl            ;index segment records
  550.     mov    bx,offset cofset     ;segment para word base
  551.     add    bx,ax            ;index to right seg.
  552.     mov    ofsptr,bx        ;save pntr for future use
  553.     mov    ax,[bx]            ;get this para value
  554.     mov    curpar,ax        ;to active para holder
  555.     mov    ax,-8[bx]        ;get segment length
  556.     mov    cl,4
  557.     shl    ax,cl            ;convt to bytes
  558.     mov    segsiz,ax        ;for ctl tbl limits
  559.     mov    dx,offset cmdbuf+3     ;dest
  560.     mov    bx,offset cmdbuf+6     ;srce
  561.     call    l03b2            ;squeeze out segment chars
  562.     ret
  563. ;
  564. segmtb    db    0ch,04h,08h,00h
  565. ;
  566. ;
  567. ;
  568. cmqiet:    mov    al,1
  569.     mov    quiflg,al        ;no screen output for now
  570.     mov    dx,offset cmdbuf+2
  571.     mov    bx,offset cmdbuf+3
  572.     call    l03b2
  573.     jmp    l01cf
  574. ;
  575. l03b2:    mov    al,[bx]    ;move cmd line
  576.     xchg    bx,dx
  577.     mov    [bx],al    ;down a notch
  578.     xchg    bx,dx
  579.     inc    bx
  580.     inc    dx
  581.     cmp    al,cr
  582.     jnz    l03b2
  583.     ret
  584. ;
  585. ;
  586. ;
  587. cmdump:    call    sgreqs
  588.     mov    dx,dmpstt
  589.     mov    bx,dmpcnt
  590.     add    bx,dx
  591.     mov    dmpend,bx
  592.     mov    bx,offset cmdbuf+3
  593.     mov    al,[bx]            ;2nd cmd char
  594.     cmp    al,cr
  595.     jz    dmphdr            ;continue last dump
  596.     cmp    al,'S'    ;53h
  597.     jnz    l0411
  598.     mov    al,1[bx]        ;next char
  599.     cmp    al,':'            ;segment req coming? 
  600.     jz    l0411            ;looks like it
  601.     jmp    dusymt
  602. ;
  603. l0411:    cmp    al,'='    ;3dh
  604.     jnz    l0418
  605.     jmp    sducnt
  606. ;
  607. l0418:    cmp    al,','    ;2ch
  608.     jz    dump1
  609. dump0:    call    gtval
  610.     push    bx
  611.     mov    bx,dmpcnt
  612.     add    bx,dx
  613.     mov    dmpend,bx
  614.     pop    bx
  615. dump1:    cmp    al,cr
  616.     jz    dump3
  617.     call    delim
  618.     inc    bx
  619.     push    dx
  620.     call    gtval
  621.     xchg    bx,dx
  622.     mov    dmpend,bx
  623.     pop    dx
  624. dump3:    mov    bx,curofs
  625.     push    bx
  626.     add    bx,dx
  627.     mov    dmpstt,bx
  628.     mov    bx,dmpend
  629.     pop    dx
  630.     add    bx,dx
  631.     mov    dmpend,bx
  632.     cmp    al,cr
  633.     jz    dmphdr
  634.     call    cmerr
  635. ;
  636. dmphdr:    call    prtstr    ;give header 
  637.     db    'Addr  +0   +2    +4   +6     +8   +A    +C   +E'
  638.     db    '     ASCII',cr,lf,0
  639. cntdmp:    mov    bx,dmpstt
  640.     mov    es,curpar
  641. dump4:    call    keychk
  642.     push    bx
  643.     sub    bx,curofs        ;remove offset for addr print
  644.     call    prword
  645.     pop    bx
  646.     push    bx
  647.     call    prspc
  648. dmpln:    mov    es,curpar
  649.     mov    al,es:[bx]
  650.     call    xo
  651.     inc    bx
  652.     mov    al,bl
  653.     and    al,1
  654.     jnz    wdspc1
  655.     call    prspc
  656. wdspc1:    mov    al,bl
  657.     and    al,3
  658.     jnz    wdspc2
  659.     call    prspc
  660. wdspc2:    mov    al,bl
  661.     and    al,7
  662.     jnz    wdspc3
  663.     call    prspc
  664. wdspc3:    mov    al,bl
  665.     and    al,0fh
  666.     jnz    dmpln
  667.     call    pstar
  668.     pop    bx
  669. dmpasc:    mov    es,curpar
  670.     mov    al,es:[bx]
  671.     cmp    al,' '    ;20h
  672.     jb    period
  673.     cmp    al,7fh
  674.     jb    chrctr
  675. period:    mov    al,'.'    ;2eh
  676. chrctr:    call    typech
  677.     inc    bx
  678.     mov    al,bl
  679.     and    al,0fh
  680.     jz    lcmplt
  681.     and    al,7
  682.     jnz    wdspc4
  683.     call    prspc
  684. wdspc4:    jmp    dmpasc
  685. ;
  686. lcmplt:    call    pstar
  687.     call    crlf
  688.     mov    dmpstt,bx
  689.     mov    ax,dmpend
  690.     sub    ax,bx
  691.     jnb    dump4
  692.     jmp    nxcmd
  693. ;
  694. sducnt:    inc    bx
  695.     call    gtval
  696.     inc    bx
  697.     dec    dx
  698.     xchg    bx,dx
  699.     mov    dmpcnt,bx
  700.     xchg    bx,dx
  701. l04e8:    cmp    al,cr
  702.     jnz    l04ef
  703.     jmp    nxcmd
  704. ;
  705. l04ef:    call    delim
  706.     jmp    dump0
  707. ;
  708. dusymt:    call    iecnt            ;init items per line
  709.     mov    bx,offset cmdbuf+4
  710.     mov    al,[bx]
  711.     cmp    al,'.'    ;2eh
  712.     jnz    frmbgn            ;no start given
  713.     call    lngth
  714.     call    locsym
  715.     jnb    frmsym
  716.     mov    bx,insloc        ;best approx
  717.     jmp    frmsym
  718. ;
  719. frmbgn:    mov    bx,offset symbas
  720. frmsym:    call    prtstr
  721.     db    'KEY: @-C=SS, D-G=DS, H-K=ES, L-O=CS, '
  722.     db    '@DHL=UNDF, AEIM=BYTE, BFJN=WORD, CGKO=DWRD',cr,lf,0
  723. agnsym:    mov    dx,[bx]            ;symbol value
  724.     inc    bx
  725.     inc    bx
  726.     inc    bx
  727.     mov    al,[bx]            ;string size
  728.     or    al,al
  729.     jz    spitcr            ;end of table reached
  730. l051a:    xchg    bx,dx
  731.     call    prword            ;output value
  732.     xchg    bx,dx
  733.     dec    bx
  734.     mov    al,[bx]            ;oprnd type byte
  735.     inc    bx
  736.     or    al,'@'            ;make printable
  737.     call    typech
  738.     mov    al,' '
  739.     call    typech
  740.     mov    ch,[bx]
  741.     mov    al,symmax+1
  742.     sub    al,ch
  743.     mov    cl,al            ;pad spaces needed
  744.     inc    bx
  745. spit:    mov    al,[bx]
  746.     call    typech
  747.     inc    bx
  748.     dec    ch
  749.     jnz    spit
  750.     mov    ch,cl
  751. spit1:    call    prspc
  752.     dec    ch
  753.     jnz    spit1
  754.     call    spcrlf
  755.     call    keychk
  756.     jmp    agnsym
  757. ;
  758. spitcr:    call    crlf
  759.     jmp    nxcmd
  760. ;
  761. spcrlf:    dec    ecnt
  762.     jz    spcry
  763.     ret
  764. ;
  765. spcry:    call    crlf
  766. ;
  767. iecnt:    mov    ecnt,4
  768.     ret
  769. ;
  770. prntos:;    call    prtstr
  771. ;    db    'Offset = ',0
  772. ;    mov    bx,curofs
  773. ;    call    prword
  774.     call    crlf
  775.     jmp    nxcmd
  776. ;
  777. ;cmofst:    call    sgreqs        ;any segment data?
  778. ;    mov    bx,offset cmdbuf+3
  779. ;    mov    al,[bx]
  780. ;    cmp    al,cr
  781. ;    jz    prntos            ;just show curr value
  782. ;    call    gtval            ;get new from user
  783. ;    cmp    al,cr
  784. ;    jz    l0557            ;that must be all
  785. ;    call    cmerr
  786. ;
  787. ;l0557:    mov    curofs,dx        ;active value in curofs
  788. ;    mov    bx,ofsptr        ;where seg rcrd keeps it
  789. ;    mov    [bx],dx            ;active segment update
  790. ;    jmp    nxcmd
  791. ;
  792. gfnam:    mov    al,wrtflg
  793.     or    al,al
  794.     jz    l056a
  795.     jmp    rrqerr
  796. ;
  797. l056a:    mov    byte ptr fcb,al
  798.     mov    byte ptr fcb+12,al
  799.     mov    bx,offset cmdbuf+3
  800.     mov    al,byte ptr cmdbuf+4
  801.     cmp    al,' '            ;20h
  802.     jnz    l057d
  803.     call    cmerr
  804. ;
  805. l057d:    cmp    al,':'            ;3ah
  806.     jnz    nodriv
  807.     mov    al,byte ptr cmdbuf+3
  808.     sub    al,'@'            ;40h
  809.     mov    byte ptr fcb,al
  810.     inc    bx
  811.     inc    bx
  812. nodriv:    mov    dx,offset fcb+1
  813.     mov    ch,8
  814.     call    mvnfld
  815.     mov    ch,3
  816.     call    mvnfld
  817.     ret
  818. ;
  819. mvnfld:    mov    al,[bx]
  820.     cmp    al,cr
  821.     jz    padfld
  822.     inc    bx
  823.     cmp    al,'.'            ;2eh
  824.     jz    padfld
  825.     xchg    bx,dx
  826.     mov    [bx],al
  827.     xchg    bx,dx
  828.     inc    dx
  829.     dec    ch
  830.     jnz    mvnfld
  831. eatfld:    mov    al,[bx]
  832.     cmp    al,cr
  833.     jnz    l05b6
  834.     ret
  835. ;
  836. l05b6:    inc    bx
  837.     cmp    al,'.'            ;2eh
  838.     jnz    eatfld
  839.     ret
  840. ;
  841. padfld:    mov    al,' '            ;20h
  842.     xchg    bx,dx
  843.     mov    [bx],al
  844.     xchg    bx,dx
  845.     inc    dx
  846.     dec    ch
  847.     jnz    padfld
  848.     ret
  849. ;
  850. ;
  851. ;
  852. cmatmt:    mov    bx,0001h
  853.     jmp    short list1
  854. ;
  855. cmbld:    mov    bx,0100h
  856.     jmp    short list1
  857. ;
  858. ;
  859. cmlist:    mov    bx,0000h
  860. list1:    mov    word ptr ascbld,bx    ;set two flags
  861.     xor    al,al
  862.     mov    wfiflg,al
  863.     mov    al,byte ptr liscnt
  864.     mov    byte ptr liscnt+1,al
  865.     mov    cntenb,al        ;assume line count range
  866.     call    sgreqs            ;check for segment spec.
  867.     mov    bx,offset cmdbuf+3
  868.     mov    al,[bx]
  869.     cmp    al,cr
  870.     jz    tenl            ;do default amount
  871.     cmp    al,','    ;2ch
  872.     jz    list3
  873.     cmp    al,' '    ;20h
  874.     jz    list3            ;first param null
  875.     cmp    al,'='    ;3dh
  876.     jnz    list2
  877.     jmp    slicnt            ;change list amount
  878. ;
  879. list2:    call    gtval            ;get first parm
  880.     mov    pcntr,dx        ;where to start
  881.     cmp    al,cr
  882.     jz    tenl            ;only start given
  883.     call    delim
  884. list3:    inc    bx            ;pass delimiter
  885.     call    gtval            ;get 2nd parm
  886.     mov    lastwd,dx        ;addr to stop at
  887.     mov    cntenb,0        ;not specific line count
  888. ;
  889. tenl:    call    keychk
  890.     test    cntenb,0ffh
  891.     jz    contl
  892.     mov    al,byte ptr liscnt+1
  893.     dec    al
  894.     jns    flagck
  895.     jmp    nxcmd
  896. ;
  897. contl:    mov    es,curpar        ;set to wanted segment
  898.     mov    ax,pcntr
  899.     sub    ax,lastwd
  900.     jb    flagck            ;not at end
  901.     jmp    nxcmd
  902. ;
  903. flagck:    test    ascbld,0ffh
  904.     jz    morel            ;not in 'A' mode
  905. builda:    mov    bx,pcntr        ;logical pointer
  906.     add    bx,curofs
  907.     mov    ch,8            ;count to believe string
  908. loop8:    mov    es,curpar
  909.     mov    al,es:[bx]
  910.     call    ifasci            ;test for db prospects
  911.     jb    morel            ;doesnt look like it
  912.     inc    bx
  913.     dec    ch
  914.     jnz    loop8            ;if need more for faith
  915. follow:    mov    es,curpar
  916.     mov    al,es:[bx]
  917.     inc    bx
  918.     call    ifasci            ;test how many more
  919.     jnb    follow
  920.     dec    bx            ;to last ascii byte +1
  921.     sub    bx,curofs        ;get logical addr
  922.     push    bx            ;save for a bit
  923.     mov    dx,pcntr        ;start addr of string
  924.     mov    al,'B'
  925.     call    enterc            ;make byte entry in ctl tbl
  926.     pop    dx            ;recover end addr
  927.     mov    al,'I'            ;back to 'I' at end
  928.     call    enterc
  929. morel:    mov    bx,doctbl
  930.     or    bx,bx
  931.     jz    ncmt            ;nothing in comment table
  932.     mov    bx,pcntr
  933.     xchg    bx,dx
  934.     call    comchk            ;test for poss. comment
  935.     jb    ncmt            ;if none
  936.     inc    bx
  937.     inc    bx            ;skip addr field
  938.     mov    ch,[bx]            ;byte count of comment
  939.     mov    al,1[bx]        ;first comment character
  940.     cmp    al,';'            ;append it?
  941.     jnz    morel1
  942.     mov    xcptr,bx        ;save for append comment
  943.     jmp    ncmt            ; dont need it now
  944. ;
  945. ;this routine prints comment like this on separate line(s)
  946. ;
  947. nwln:    stc                ;semic to start
  948. nwln0:    mov    wfiflg,1
  949.     jnb    ncsemi
  950.     call    semic            ;start with semicolon
  951. ncsemi:    or    ch,ch
  952.     jnz    cntcmt            ;if non zero count
  953.     ret
  954. ;
  955. cntcmt:    inc    bx            ;update pntr
  956.     mov    al,[bx]
  957.     cmp    al,'\'            ;'\' for multi-line comment
  958.     jnz    ntbksl
  959.     call    crlf            ;break comment here
  960.     dec    ch
  961.     jmp    nwln0
  962. ;
  963. ntbksl:    call    typech
  964.     dec    ch
  965.     jnz    cntcmt
  966.     ret
  967. ;
  968. morel1:    cmp    al,'*'            ;substitute comment?
  969.     jnz    morel2
  970.     mov    rplptr,bx        ;comment replaces instr
  971.     jmp    ncmt            ;but not right now
  972. ;
  973. morel2:    call    nwln            ;put out the comment
  974.     call    crlf
  975. ;
  976. ncmt:    mov    dx,pcntr
  977.     call    ctlook            ;find ctrl entry for this addr
  978.     pushf
  979.     dec    bx            ;back to prev mode for default
  980.     popf
  981.     jb    cml15            ;not matched addr, use prev mode
  982.     add    bx,4            ;use matched addr mode
  983. cml15:    mov    al,[bx]            ;mode char
  984.     cmp    al,'I'            ;49h
  985.     jz    ictl            ;do instruction list
  986.     cmp    al,'E'            ;45h
  987.     jnz    l06fd
  988.     jmp    cmeof            ;show end & stop
  989. ;
  990. l06fd:    push    ax
  991.     inc    bx            ;to next ctl rec base
  992.     mov    dx,1[bx]        ;addr value
  993.     push    dx
  994.     mov    bx,pcntr
  995.     xchg    bx,dx
  996.     call    hsym            ;check for any label
  997.     pop    bx
  998.     mov    nxtctl,bx        ;save addr to recheck ctrl
  999.     xchg    bx,dx
  1000.     mov    wfiflg,0
  1001.     pop    ax
  1002.     cmp    al,'S'             ;space (rs) mode?
  1003.     jnz    ckbmd
  1004.     jmp    dsmode
  1005. ;
  1006. ckbmd:    cmp    al,'B'            ;byte mode?
  1007.     jnz    ckhmd
  1008.     jmp    bmode
  1009. ;
  1010. ckhmd:    cmp    al,'H'            ;force hex bytes?
  1011.     jnz    ckwmd
  1012.     jmp    hmode
  1013. ;
  1014. ckwmd:    cmp    al,'W'            ;word mode?
  1015.     jnz    badmd
  1016.     jmp    wmode
  1017. ;
  1018. badmd:    call    typech
  1019.     call    prtstr
  1020.     db    ': INVALID CTL ENTRY',cr,lf,0
  1021.     jmp    nxcmd
  1022. ;
  1023. ictl:    call    dline            ;disasm one instruction
  1024.     mov    wfiflg,0
  1025.     jmp    tenl
  1026. ;
  1027. slicnt:    inc    bx
  1028.     call    gtval
  1029.     mov    al,dl            ;one byte value
  1030.     or    al,al            ;test if legal
  1031.     jnz    l0762
  1032.     call    cmerr
  1033. ;
  1034. l0762:    mov    byte ptr liscnt,al    ;save line count
  1035.     mov    byte ptr liscnt+1,al    ;for curr use
  1036.     mov    al,[bx]            ;what ended value
  1037.     inc    bx
  1038. l0776:    cmp    al,cr            ;only define?
  1039.     jnz    l077d
  1040.     jmp    nxcmd
  1041. ;
  1042. l077d:    call    delim
  1043.     jmp    list2
  1044. ;
  1045. dsmode:    push    dx
  1046.     mov    bx,pcntr
  1047.     neg    bx
  1048.     add    bx,dx
  1049.     mov    wfiflg,1
  1050.     call    pstg
  1051.     db    'RS',9,0
  1052.     mov    al,bh
  1053.     call    xo0
  1054.     mov    al,bl
  1055.     call    xo
  1056.     mov    al,'H'            ;48h
  1057.     call    typech
  1058.     call    dcrlf
  1059.     pop    bx
  1060.     mov    pcntr,bx
  1061.     jmp    tenl
  1062. ;
  1063. wmode:    mov    al,1
  1064.     mov    wfiflg,al
  1065.     call    pstg
  1066.     db    'DW',9,0
  1067.     mov    bx,pcntr
  1068.     add    bx,curofs
  1069.     mov    es,curpar
  1070.     mov    dx,es:[bx]
  1071.     call    prntde
  1072.     call    crlf
  1073.     mov    bx,pcntr
  1074.     inc    bx
  1075.     inc    bx
  1076.     mov    pcntr,bx
  1077.     jmp    tenl
  1078. ;
  1079. stpln:    call    dcrlf
  1080.     jmp    tenl
  1081. ;
  1082. hmode:    xor    al,al
  1083.     jmp    short bmode1
  1084. ;
  1085. bmode:    mov    al,0ffh
  1086. bmode1:    mov    adb,al            ;set subtype flag
  1087.     mov    strcnt,0
  1088.     mov    wfiflg,1
  1089.     mov    bx,pcntr
  1090.     add    bx,curofs
  1091.     test    adb,0ffh
  1092.     mov    es,curpar
  1093.     mov    al,es:[bx]
  1094.     jz    nprtc
  1095.     cmp    al,' '            ;20h
  1096.     jb    nprtc            ;cant print ctrl codes
  1097.     cmp    al,7fh
  1098.     jnb    nprtc            ;also unprintable
  1099.     jmp    conasc
  1100. ;
  1101. nprtc:    call    pstg
  1102.     db    'DB',9,0
  1103.     xor    al,al
  1104.     mov    strcnt,al
  1105. morinv:    mov    es,curpar
  1106.     mov    al,es:[bx]
  1107.     cmp    al,lf
  1108.     jb    ltlf
  1109.     call    xo0
  1110.     mov    al,'H'            ;48h
  1111.     call    typech
  1112.     mov    al,strcnt
  1113.     add    al,2
  1114.     mov    strcnt,al
  1115.     jmp    mvup
  1116. ;
  1117. ltlf:    or    al,'0'            ;30h
  1118.     call    typech
  1119. mvup:    inc    bx
  1120.     mov    dx,pcntr
  1121.     inc    dx
  1122.     mov    pcntr,dx
  1123.     cmp    dx,nxtctl
  1124.     jnz    trysym
  1125.     jmp    qtb
  1126. ;
  1127. trysym:    mov    bx,pcntr
  1128.     xchg    bx,dx
  1129.     call    symluk
  1130.     jb    nstpln
  1131.     jmp    stpln
  1132. nstpln:    mov    al,strcnt
  1133.     add    al,2
  1134.     mov    strcnt,al
  1135.     cmp    al,25
  1136.     jb    l0864
  1137.     jmp    stpln
  1138. ;
  1139. l0864:    mov    bx,pcntr
  1140.     add    bx,curofs
  1141.     test    adb,0ffh
  1142.     jz    nxinv
  1143.     mov    es,curpar
  1144.     mov    al,es:[bx]
  1145.     cmp    al,' '            ;20h            
  1146.     jb    nxinv
  1147.     cmp    al,7fh
  1148.     jnb    nxinv
  1149.     jmp    stpln
  1150. ;
  1151. nxinv:    mov    al,','            ;2ch
  1152.     call    typech
  1153.     jmp    morinv
  1154. ;
  1155. conasc:    call    pstg
  1156.     db    'DB',9,0
  1157.     mov    strcnt,0
  1158.     mov    al,''''            ;27h
  1159.     call    typech
  1160.     add    strcnt,1
  1161.     mov    es,curpar
  1162.     mov    al,es:[bx]
  1163. morasc:    call    typech
  1164.     mov    es,curpar
  1165.     mov    al,es:[bx]
  1166.     cmp    al,''''            ;27h
  1167.     jnz    l08ac
  1168.     call    typech
  1169. l08ac:    inc    bx
  1170.     mov    dx,pcntr
  1171.     inc    dx
  1172.     mov    pcntr,dx
  1173.     cmp    dx,nxtctl
  1174.     jz    fnlqt
  1175. yet:    push    bx
  1176.     mov    bx,pcntr
  1177.     xchg    bx,dx
  1178.     call    symluk
  1179.     pop    bx
  1180.     jnb    fnlqt
  1181.     mov    al,strcnt
  1182.     inc    al
  1183.     mov    strcnt,al
  1184.     cmp    al,35            ;23h
  1185.     jnb    lastqt
  1186.     cmp    al,25
  1187.     jb    still
  1188.     dec    bx
  1189.     mov    es,curpar
  1190.     mov    al,es:[bx]
  1191.     inc    bx
  1192.     cmp    al,' '            ;20h
  1193.     jz    fnlqt
  1194. still:    mov    es,curpar
  1195.     mov    al,es:[bx]
  1196.     cmp    al,' '            ;20h
  1197.     jb    lastqt
  1198.     cmp    al,7fh
  1199.     jb    morasc
  1200. lastqt:    mov    al,''''            ;27h
  1201.     call    typech
  1202.     jmp    stpln
  1203. ;
  1204. fnlqt:    mov    al,''''            ;27h
  1205.     call    typech
  1206. qtb:    call    dcrlf
  1207.     jmp    tenl
  1208. ;
  1209. ;
  1210. ;
  1211. cmstts:    call    prtstr
  1212.     db    'SYMTBL='
  1213.     db    0
  1214.     mov    bx,offset symbas
  1215.     call    prword
  1216.     mov    bx,symtp
  1217.     call    prword
  1218.     call    crlf
  1219.     call    prtstr
  1220.     db    'PC    =',0
  1221.     mov    bx,pcntr
  1222.     call    prword
  1223.     mov    bx,hiload
  1224.     call    prword
  1225.     call    crlf
  1226.     call    prtstr
  1227.     db    'PARA  =',0
  1228.     mov    bx,curpar
  1229.     call    prword
  1230.     call    crlf
  1231.     mov    bx,doctbl
  1232.     or    bx,bx
  1233.     jz    nodoct
  1234.     call    prtstr
  1235.     db    'COMNTS='
  1236.     db    0
  1237.     mov    bx,doctbl
  1238.     call    prword
  1239.     mov    bx,docend
  1240.     call    prword
  1241.     call    crlf
  1242. nodoct:    call    prtstr
  1243.     db    'CTLTBL='
  1244.     db    0
  1245.     mov    bx,offset ctlbas
  1246.     call    prword
  1247. l0984:    mov    ax,1[bx]
  1248.     and    al,ah
  1249.     add    bx,4
  1250.     inc    al
  1251.     jnz    l0984
  1252.     sub    bx,4
  1253.     call    prword
  1254.     call    crlf
  1255. ;
  1256.     call    prtstr
  1257.     db    'SEG. LGTH BASE SMIN SMAX PARA',cr,lf,0
  1258.     mov    bx,offset cstbl
  1259. sgplp:    mov    al,[bx]
  1260.     or    al,al
  1261.     jz    sgpen            ;found end flag
  1262.     cmp    al,' '            ;used entry?
  1263.     jnz    usdseg
  1264.     add    bx,12
  1265.     jmp    short sgplp
  1266. usdseg:    mov    ch,2
  1267.     call    pstrg            ;segment label & order nr
  1268.     call    prtstr
  1269.     db    ':  ',0
  1270.     call    prwval
  1271.     call    prwval
  1272.     call    prwval
  1273.     call    prwval
  1274.     call    prwval
  1275.     call    crlf
  1276.     jmp    short sgplp
  1277. ;
  1278. sgpen:    jmp    nxcmd
  1279. ;
  1280. prwval:    mov    dx,[bx]
  1281.     xchg    bx,dx
  1282.     call    prword
  1283.     xchg    bx,dx
  1284.     inc    bx
  1285.     inc    bx
  1286.     ret
  1287. ;
  1288. ;
  1289. ;
  1290. cmfind:    call    sgreqs
  1291.     mov    bx,offset cmdbuf+3
  1292.     mov    al,[bx]
  1293.     cmp    al,cr
  1294.     jz    prevf
  1295.     call    gtval
  1296.     xchg    bx,dx
  1297.     mov    fndadd,bx
  1298.     mov    bx,curofs
  1299.     mov    fndpc,bx
  1300.     xchg    bx,dx
  1301.     cmp    al,cr
  1302.     jz    prevf
  1303.     call    delim
  1304. l09c6:    inc    bx
  1305.     call    gtval
  1306.     cmp    al,cr
  1307.     jz    l09d1
  1308.     call    cmerr
  1309. ;
  1310. l09d1:    mov    es,curpar
  1311.     mov    bx,curofs
  1312.     add    bx,dx
  1313.     mov    fndpc,bx
  1314. prevf:    mov    bx,fndadd
  1315.     xchg    bx,dx
  1316. nyet:    call    keychk
  1317. ;add topchk here
  1318.     mov    bx,fndpc
  1319.     mov    es,curpar
  1320.     mov    al,es:[bx]
  1321.     inc    bx
  1322.     mov    fndpc,bx
  1323.     cmp    al,dl
  1324.     jnz    nyet
  1325.     mov    es,curpar
  1326.     mov    al,es:[bx]
  1327.     cmp    al,dh
  1328.     jnz    nyet
  1329.     push    bx
  1330.     push    dx
  1331.     sub    bx,curofs
  1332.     dec    bx
  1333.     call    prword
  1334.     pop    dx
  1335.     pop    bx
  1336.     call    prspc
  1337.     jmp    nyet
  1338. ;topchk can be put here
  1339. ;
  1340. ;
  1341. cmeof:    call    hsym
  1342.     mov    wfiflg,1
  1343.     call    pstg
  1344.     db    'END',cr,lf,0
  1345.     xor    al,al
  1346.     mov    wfiflg,al
  1347.     mov    al,wrtflg
  1348.     or    al,al
  1349.     jnz    l0a35
  1350.     jmp    nxcmd
  1351. ;
  1352. l0a35:    mov    al,1ah
  1353.     call    wtfchr
  1354.     call    flushf
  1355.     xor    al,al
  1356.     mov    wrtflg,al
  1357.     call    prtstr
  1358.     db    '++ASM FILE CLOSED++',cr,lf,0
  1359.     jmp    nxcmd
  1360. ;
  1361. ;
  1362. ;
  1363. cmread:
  1364.     call    gfnam
  1365.     mov    al,wrtflg
  1366.     or    al,al
  1367.     jz    rdaprv            ; ok to read, now write current
  1368.     jmp    rrqerr
  1369. ;
  1370. rdaprv:    mov    bx,offset fcb+9
  1371.     mov    dx,offset litall
  1372.     mov    cl,3
  1373.     call    cmpstr
  1374.     jz    wntall            ;not rqst to load all
  1375.     jmp    ntlall
  1376. wntall:    call    lodall            ;callable due to cmd line use
  1377.     jmp    cmstts
  1378. ;
  1379. lodall:    mov    bx,offset litcmd
  1380.     call    chgtyp
  1381.     call    prtstr
  1382.     db    cr,lf,'Reading .COM file..',cr,lf,0
  1383.     call    lodcmd
  1384. ;
  1385.     mov    bx,offset litdoc
  1386.     call    chgtyp
  1387.     call    prtstr
  1388.     db    cr,lf,'Reading .DOC file..',cr,lf,0
  1389.     call    loddoc
  1390. ;
  1391.     mov    bx,offset litctl
  1392.     call    chgtyp
  1393.     call    prtstr
  1394.     db    cr,lf,'Reading .CTL file..',cr,lf,0
  1395.     call    lodctl
  1396. ;
  1397.     mov    bx,offset litsym
  1398.     call    chgtyp
  1399.     call    prtstr
  1400.     db    cr,lf,'Reading .SMB file..',cr,lf,0
  1401.     call    lodsym
  1402.     ret
  1403. ;
  1404. chgtyp:    mov    dx,offset fcb+9
  1405.     mov    ch,3
  1406.     mov    fcb+12,0        ;clear extent
  1407.     jmp    mvnfld
  1408. ;
  1409. ntlall:    mov    bx,offset fcb+9
  1410.     mov    dx,offset litsym
  1411.     mov    cl,3
  1412.     call    cmpstr
  1413.     jnz    l0a8a
  1414.     mov    bx,offset symbas
  1415.     call    ldasfl
  1416.     jnc    symffd
  1417.     jmp    nxcmd
  1418. symffd:    call    ldsym2
  1419.     jmp    cmstts
  1420. ;
  1421. l0a8a:    mov    bx,offset fcb+9
  1422.     mov    dx,offset litcmd
  1423.     mov    cl,3
  1424.     call    cmpstr
  1425.     jz    wntcmd
  1426.     jmp    l0adc
  1427. wntcmd:    call    lodcmd
  1428.     jmp    nxcmd
  1429. ;
  1430. lodcmd:    call    fopen            ; locate the prog image
  1431.     jnc    cmdlds            ; found one to load
  1432.     ret
  1433. ;
  1434. cmdlds:    call    erstbl            ; start clean
  1435.     mov    ax,mcbbas
  1436.     or    ax,ax
  1437.     jz    modofs
  1438. ;    push    es
  1439. ;    mov    es,ax
  1440. ;    mov    ah,49h            ; release memory
  1441. ;    call    bdos
  1442. ;    pop    es
  1443. modofs:    
  1444.     xor    dx,dx
  1445.     mov    ax,word ptr fcb+10h     ; the small part of file (com file)
  1446.     mov    cx,16
  1447.     div    cx            ; convert to paras
  1448.     adc    ax,0            ; any carry
  1449.     mov    mcbsiz,ax        ;how much we want
  1450.     mov    bx,ax
  1451. ;    mov    ah,48h            ;memory request
  1452. ;    call    bdos
  1453. ;    jnc    mrqok            ;if granted
  1454. ;    call    prtstr
  1455. ;    db    'Memory Allocation Error',7,0dh,0ah,0
  1456. ;    jmp    nxcmd
  1457.  
  1458.     mov    bx,offset symbas
  1459.     sub    bx,100h            ; size of program
  1460.     mov    cl,4
  1461.     shr    bx,cl
  1462.     add    bx,640            ; size of pgm in paras + 10K sym area
  1463.     mov    ax,cs
  1464.     add    ax,bx            ; convert to segment
  1465. mrqok: 
  1466.     mov    mcbbas,ax        ; save segment
  1467.     mov    curpar,ax
  1468.  
  1469. ; Now have to build a FAKE segment table for the com file
  1470.  
  1471.     mov    bx,offset fake_comtbl
  1472.     mov    dx,offset cstbl
  1473.     mov    ax,mcbsiz
  1474.     mov    [bx+1],ax
  1475.     mov    [bx+10],ax
  1476.     mov    [bx+19],ax
  1477.     mov    [bx+28],ax
  1478.     mov    ax,mcbbas
  1479.     mov    [bx+3],ax
  1480.     mov    [bx+12],ax
  1481.     mov    [bx+21],ax
  1482.     mov    [bx+30],ax
  1483. cmhlp:
  1484.     mov    al,[bx]            ; segment type byte
  1485.     inc    bx
  1486.     add    al,al
  1487.     jz    set_dmablk
  1488.     inc    nrsegs
  1489.     push    bx            ; save hdr ptr around move
  1490.     sub    ah,ah
  1491.     mov    bx,offset segnam-2    ; no type 0
  1492.     add    bx,ax
  1493.     mov    cx,bx
  1494.     xchg    bx,dx
  1495.     mov    [bx],cx            ; seg name in place
  1496.     xchg    bx,dx
  1497.     inc    dx
  1498.     inc    dx
  1499.     pop    bx            ; hdr ptr back
  1500.     mov    ch,4            ; words to move
  1501. cmhmlp:
  1502.     mov    ax,[bx]            ; move seg data
  1503.     xchg    bx,dx
  1504.     mov    [bx],ax            ; into table area
  1505.     xchg    bx,dx
  1506.     add    bx,2
  1507.     add    dx,2
  1508.     dec    ch
  1509.     jnz    cmhmlp
  1510.     add    dx,2            ; skip over para in table
  1511.     jmp    short cmhlp
  1512.  
  1513. set_dmablk:
  1514.     sub    dx,dx            ;cheap 0
  1515.     mov    cofset,dx
  1516. comrd_lp:
  1517.     mov    ax,mcbbas
  1518.     push    ds
  1519.     mov    ds,ax            ; segment will be here
  1520.     mov    ah,26
  1521.     call    bdos            ;dma offset = 0
  1522.     pop    ds
  1523.     mov    dx,offset fcb
  1524.     mov    ah,14h            ;read data to mem
  1525.     call    bdos
  1526.     or    al,al
  1527.     jnz    l0ac4            ;end or trbl
  1528.     mov    dx,cofset
  1529.     add    dx,128            ; + 128 bytes
  1530.     mov    cofset,dx
  1531.     jmp    short comrd_lp
  1532.     
  1533. l0ac4:
  1534.     mov    word ptr cofset,0    ; restore offset
  1535.     mov    bx,mcbsiz
  1536.     call    prword            ;total file size in para
  1537.     call    crlf
  1538.     call    fclose
  1539.     mov    dx,offset tbuf
  1540.     mov    ah,1ah
  1541.     call    bdos            ;restore dma offset
  1542.     mov    word ptr pcntr,0h    ; set program counter
  1543.     ret
  1544. ;
  1545. ;
  1546. l0adc:    mov    bx,offset fcb+9
  1547.     mov    dx,offset litctl
  1548.     mov    cl,3
  1549.     call    cmpstr
  1550.     jnz    l0aec
  1551.     call    lodctl
  1552.     jmp    nxcmd
  1553. ;
  1554. l0aec:    mov    bx,offset fcb+9
  1555.     mov    dx,offset litdoc
  1556.     mov    cl,3
  1557.     call    cmpstr
  1558.     jz    doclod
  1559.     call    cmerr
  1560. ;
  1561. doclod:    call    l1041            ;check for space assigned
  1562.     mov    bx,doctbl
  1563.     mov    sdflg,1            ;flag no type byte
  1564.     call    ldasfl
  1565.     jnb    gotdoc            ;if good read
  1566.     jmp    nxcmd
  1567. gotdoc:    call    lddoc2
  1568.     jmp    cmstts
  1569. ;
  1570. lodsym:    mov    bx,offset symbas    ;table start
  1571.     mov    sdflg,0            ;flag for symb type
  1572.     call    ldasfl            ;file data to memory
  1573. ldsym2:    mov    symtp,bx
  1574.     mov    byte ptr 3[bx],0     ;zero count = end flag
  1575.     ret
  1576. ;
  1577. loddoc:    call    l1041
  1578.     mov    sdflg,1
  1579.     call    ldasfl
  1580.     jnb    lddoc2
  1581.     ret
  1582. ;
  1583. lddoc2:    mov    docend,bx
  1584.     mov    word ptr [bx],0ffffh
  1585.     ret
  1586. ;
  1587. ;
  1588. ldasfl:    call    fopen
  1589.     jnc    skppre
  1590.     ret
  1591. skppre:    call    rdfchr
  1592.     cmp    al,1ah
  1593.     jnz    l0b6c
  1594.     push    bx
  1595.     call    fclose
  1596.     pop    bx
  1597.     ret
  1598. l0b6c:    cmp    al,' '
  1599.     jb    skppre            ;ignore ctrl chars
  1600.     call    hexbin
  1601.     mov    [bx],dx            ;value word
  1602.     inc    bx
  1603.     inc    bx
  1604.     test    sdflg,1
  1605.     jnz    drdsk1            ;if no type byte
  1606.     call    rdfchr
  1607.     mov    [bx],al            ;type byte
  1608.     inc    bx
  1609.     call    rdfchr            ;eat delim space
  1610. drdsk1:    push    bx            ;save locn for count
  1611.     inc    bx
  1612.     mov    ch,0
  1613. lpasld:    call    rdfchr
  1614.     cmp    al,9
  1615.     jz    ldassp
  1616.     cmp    al,cr            ;found delim
  1617.     jz    ldassp
  1618.     mov    [bx],al
  1619.     inc    bx
  1620.     inc    ch            ;char count
  1621.     jmp    lpasld
  1622. ;
  1623. ldassp:    pop    si
  1624.     xchg    bx,si
  1625.     push    si
  1626.     mov    [bx],ch            ;store byte count
  1627.     pop    bx
  1628.     jmp    skppre            ;for another
  1629. ;
  1630. hexbin:    mov    dx,0
  1631. l0ba3:    cmp    al,' '            ;20h
  1632.     jnz    l0ba8
  1633.     ret
  1634. ;
  1635. l0ba8:    cmp    al,1ah
  1636.     jnz    l0baf
  1637.     jmp    l0d20
  1638. ;
  1639. l0baf:    cmp    al,'9'+1
  1640.     jb    l0bb5
  1641.     sub    al,7
  1642. l0bb5:    sub    al,'0'            ;30h
  1643.     xchg    bx,dx
  1644.     add    bx,bx
  1645.     add    bx,bx
  1646.     add    bx,bx
  1647.     add    bx,bx
  1648.     add    al,bl
  1649.     mov    bl,al
  1650.     xchg    bx,dx
  1651.     call    rdfchr
  1652.     cmp    al,1ah
  1653.     jnz    l0ba3
  1654.     jmp    l0d20
  1655. ;
  1656. erstbl:    mov    bx,offset cstbl
  1657.     mov    nrsegs,0
  1658.     mov    ch,8
  1659. etlp1:    mov    cl,5
  1660.     mov    ax,'  '
  1661. etlp2:    mov    [bx],ax
  1662.     xor    ax,ax
  1663.     inc    bx
  1664.     inc    bx
  1665.     dec    cl
  1666.     jnz    etlp2
  1667.     inc    bx
  1668.     inc    bx
  1669.     dec    ch
  1670.     jnz    etlp1
  1671.     ret
  1672. ;
  1673. ;
  1674. ;
  1675. cmsave:    call    gfnam
  1676.     mov    al,wrtflg
  1677.     or    al,al
  1678.     jz    savok
  1679.     jmp    rrqerr
  1680. ;
  1681. savok:    mov    bx,offset fcb+9
  1682.     mov    dx,offset litall
  1683.     mov    cl,3
  1684.     call    cmpstr
  1685.     jz    allsav
  1686.     jmp    ntsall
  1687. ;
  1688. allsav:    mov    dx,docend
  1689.     mov    bx,doctbl
  1690.     cmp    bx,dx
  1691.     jz    nosdoc
  1692.     mov    bx,offset litdoc
  1693.     call    chgtyp
  1694.     call    prtstr
  1695.     db    cr,lf,'Saving .DOC file..',cr,lf,0
  1696.     call    savdoc
  1697. nosdoc:    mov    dx,symtp
  1698.     mov    bx,offset symbas
  1699.     cmp    bx,dx
  1700.     jz    nossym
  1701.     mov    bx,offset litsym
  1702.     call    chgtyp
  1703.     call    prtstr
  1704.     db    cr,lf,'Saving .SMB file..',cr,lf,0
  1705.     call    symsav
  1706. nossym:    mov    dx,ctltop
  1707.     mov    bx,offset ctlbas
  1708.     cmp    bx,dx
  1709.     jnz    havctl
  1710.     jmp    nxcmd
  1711. havctl:    mov    bx,offset litctl
  1712.     call    chgtyp
  1713.     call    prtstr
  1714.     db    cr,lf,'Saving .CTL file..',cr,lf,0
  1715.     jmp    savctl
  1716. ;
  1717. ntsall:    mov    bx,offset fcb+9
  1718.     mov    dx,offset litsym
  1719.     mov    cl,3
  1720.     call    cmpstr
  1721.     jnz    ntssym
  1722.     call    symsav
  1723.     jmp    nxcmd
  1724. ;
  1725. ntssym:    mov    bx,offset fcb+9
  1726.     mov    dx,offset litctl
  1727.     mov    cl,3
  1728.     call    cmpstr
  1729.     jnz    ntsctl
  1730.     jmp    svctl0
  1731. ;
  1732. ntsctl:    mov    bx,offset fcb+9
  1733.     mov    dx,offset litdoc
  1734.     mov    cl,3
  1735.     call    cmpstr
  1736.     jnz    ntsdoc
  1737.     call    savdoc
  1738.     jmp    nxcmd
  1739. ;
  1740. symsav:    mov    bx,offset symbas
  1741.     mov    sdflg,0            ;symbol mode, not .doc
  1742. l0bf4:    call    creatf
  1743. l0bf7:    mov    dx,[bx]            ;address value
  1744.     inc    bx
  1745.     test    sdflg,1
  1746.     jnz    sdskp1            ;if .doc, no type byte
  1747.     inc    bx
  1748.     mov    ah,[bx]            ;symbol type byte
  1749. sdskp1:    inc    bx
  1750.     mov    al,[bx]    ;string length
  1751.     inc    bx
  1752.     mov    ch,al
  1753.     or    al,al
  1754.     jz    oufend    ;end of table found
  1755.     push    ax            ;protect type byte
  1756.     call    outadr
  1757.     mov    al,' '    ;20h
  1758.     call    wtfchr
  1759.     pop    ax
  1760.     test    sdflg,1
  1761.     jnz    l0c0c            ;if .doc mode
  1762.     mov    al,ah
  1763.     or    al,'@'            ;make type printable
  1764.     call    wtfchr
  1765.     mov    al,' '
  1766.     call    wtfchr
  1767. l0c0c:    mov    al,[bx]
  1768.     call    wtfchr            ;output string char
  1769.     inc    bx
  1770.     dec    ch
  1771.     jnz    l0c0c
  1772.     mov    al,cr
  1773.     call    wtfchr            ;end of line
  1774.     mov    al,lf
  1775.     call    wtfchr
  1776.     jmp    l0bf7
  1777. ;
  1778. oufend:    mov    al,1ah
  1779.     call    wtfchr            ;end of file
  1780.     call    flushf
  1781.     ret
  1782. ;
  1783. ntsdoc:    mov    bx,offset fcb+9
  1784.     mov    dx,offset lita86
  1785.     mov    cl,3
  1786.     call    cmpstr
  1787.     jz    sava86
  1788.     call    cmerr
  1789. ;
  1790. outadr:    mov    al,dh
  1791.     call    hexl
  1792.     call    wtfchr
  1793.     mov    al,dh
  1794.     call    hexr
  1795.     call    wtfchr
  1796.     mov    al,dl
  1797.     call    hexl
  1798.     call    wtfchr
  1799.     mov    al,dl
  1800.     call    hexr
  1801.     jmp    wtfchr
  1802. ;
  1803. sava86:    mov    al,1
  1804.     mov    wrtflg,al
  1805.     xor    al,al
  1806.     mov    wfiflg,al
  1807.     call    creatf
  1808.     call    prtstr
  1809.     db    '++WRITING .ASM ENABLED',cr,lf
  1810.     db    'USE Z COMMAND OR E CONTROL TO CLOSE FILE++',cr,lf,0
  1811.     jmp    nxcmd
  1812. ;
  1813. savdoc:    call    l1041
  1814.     mov    bx,docend
  1815.     mov    sdflg,1
  1816.     inc    bx
  1817.     inc    bx
  1818.     inc    bx
  1819.     mov    byte ptr [bx],0
  1820.     mov    bx,doctbl
  1821.     jmp    l0bf4
  1822. ;
  1823. rrqerr:    call    prtstr
  1824.     db    '++NO FILE ACCESSES PERMITTED '
  1825.     db    'UNTIL .ASM CLOSED'
  1826.     db    cr,lf,0
  1827.     jmp    nxcmd
  1828. ;
  1829. l0d20:    call    prtstr
  1830.     db    '++UNEXPECTED EOF'
  1831.     db    cr,lf,0
  1832.     jmp    nxcmd
  1833. ;
  1834. ;
  1835. ;
  1836. ;    control table structure as of 12/25/84
  1837. ;    4 byte entries, 1 byte segment char,
  1838. ;    2 byte binary address, 1 byte mode char
  1839. ;    table terminated by 0ffffh in address bytes
  1840. ;
  1841. cmctl:    call    sgreqs
  1842.     mov    bx,offset cmdbuf+3
  1843.     mov    al,[bx]
  1844.     cmp    al,cr
  1845.     jnz    l0d45            ;have more info
  1846.     jmp    clist0            ;just list them all
  1847. ;
  1848. l0d45:    call    gtval
  1849.     cmp    al,cr
  1850.     jnz    l0d4f            ;more than one item
  1851.     jmp    l0e65            ;partial list
  1852. ;
  1853. l0d4f:    call    delim
  1854. l0d5a:    inc    bx
  1855.     mov    al,[bx]            ;letter to use comes next
  1856.     call    entrc4            ;make a manual entry
  1857.     jmp    nxcmd
  1858. ;
  1859. enterc:    push    bx            ;make entry from 'A' function
  1860.     push    dx            ;pcntr to locate
  1861.     push    ax            ;mode char in al
  1862.     call    ctlook            ;search ctl table
  1863.     pushf
  1864.     dec    bx            ;back to prev mode char
  1865.     popf                ;flags restored
  1866.     jb    entrc2            ;if table end or past right addr
  1867.     add    bx,4            ;pnt to curr mode char
  1868. entrc2:    pop    ax            ;char wanted
  1869.     pop    dx            ;and pcntr value
  1870.     cmp    al,[bx]            ;cmpar to current entry
  1871.     pop    bx            ;stack in order
  1872.     jnz    entrc4            ;is a needed entry
  1873.     ret            ;nothing to do
  1874. ;
  1875. entrc4:    mov    typndx,al    ;save ctrl char
  1876.     call    ctlook        ;find place for it
  1877.     jnb    l0d84        ;matches an existing entry
  1878.     jmp    entrc5        ;go make a new entry
  1879. ;
  1880. l0d84:    mov    al,typndx    ;recover the char
  1881.     call    cltrck        ;test all legal values
  1882.     cmp    al,'K'
  1883.     jz    l0dba        ;want kill
  1884.     jmp    l0e34        ;modify existing entry
  1885. l0dba:    mov    ax,1[bx]    ;addr field of rec
  1886.     and    al,ah
  1887.     inc    al
  1888.     jz    l0bf5        ;if at table end
  1889.     mov    ch,4        ;record size
  1890. l0dc6:    mov    al,4[bx]        ;move from higher rec
  1891.     mov    [bx],al        ;down to lower rec
  1892.     inc    bx
  1893.     dec    ch        ;until record moved
  1894.     jnz    l0dc6
  1895.     jmp    l0dba        ;repeat for rest of recs
  1896. ;
  1897. cltrck:    cmp    al,'K'
  1898.     jz    cltrrt
  1899. ctlck2:    cmp    al,'E'
  1900.     jz    cltrrt
  1901.     cmp    al,'B'
  1902.     jz    cltrrt
  1903.     cmp    al,'H'
  1904.     jz    cltrrt
  1905.     cmp    al,'W'
  1906.     jz    cltrrt
  1907.     cmp    al,'I'
  1908.     jz    cltrrt
  1909.     cmp    al,'S'
  1910.     jz    cltrrt
  1911.     call    cmerr
  1912. ;
  1913. cltrrt:    ret
  1914. ;
  1915. l0bf5:    sub    bx,4        ;base of last valid entry
  1916.     jmp    nodoct
  1917. ;
  1918. entrc5:    mov    al,typndx    ; want to add a record
  1919.     call    ctlck2        ;test for legal to store
  1920.     push    dx        ; addr val to store
  1921.     push    bx        ; where to put new record
  1922.     mov    bx,offset ctlbas ;first field table end
  1923. entrc7:    mov    ax,1[bx]    ; addr value this entry
  1924.     add    bx,4        ; to start next rcrd
  1925.     and    al,ah        ;combine bytes
  1926.     inc    al        ;test for end flag
  1927.     jnz    entrc7        ;not at end, srch more
  1928.     mov    dx,bx        ;copy it
  1929.     add    dx,4        ;space for new record
  1930.     pop    cx        ;table insert location
  1931. entrc8:    dec    bx
  1932.     dec    dx
  1933.     mov    al,[bx]        ;old entry byte
  1934.     xchg    bx,dx
  1935.     mov    [bx],al        ; to new place higher
  1936.     xchg    bx,dx
  1937.     cmp    dx,cx        ;at insert location yet?
  1938.     jnz    entrc8        ; till there
  1939.     mov    bx,cx        ;restore tbl pntr
  1940.     pop    dx        ; pcntr value to place
  1941.     mov    ch,segsho    ;segment char
  1942.     mov    [bx],ch
  1943.     mov    1[bx],dx    ;store address value
  1944.     mov    al,typndx
  1945.     mov    3[bx],al    ;store mode letter
  1946.     add    bx,4
  1947.     ret
  1948. ;
  1949. l0e34:    mov    ah,segsho    ;segment char
  1950.     mov    [bx],ah        ;groups entry
  1951.     mov    3[bx],al    ;modify existing entry
  1952.     ret
  1953. ;
  1954. ctlook:    mov    bx,offset ctlbas ;table start
  1955.     mov    ch,segsho
  1956. ctlk2:    mov    ax,1[bx]    ;addr value
  1957.     and    al,ah        ;addr hi byte
  1958.     inc    al        ;test for ffff
  1959.     stc            ;to show end of tbl
  1960.     jnz    l0e4s        ;wasnt the end flag
  1961.     ret
  1962. ;
  1963. l0e4s:    cmp    ch,[bx]
  1964.     jz    l0e48        ; in right segment
  1965. l0e5c:    jnb    ctlk4        ;still too low in tbl
  1966.     ret            ;too far, stop
  1967. ;
  1968. l0e48:    cmp    dx,1[bx]
  1969.     jnz    l0e5c
  1970.     ret            ;found exact match
  1971. ;
  1972. ctlk4:    add    bx,4        ;step an entry worth
  1973.     jmp    short ctlk2        ;try another entry
  1974. ;
  1975. ;
  1976. l0e65:    call    iecnt
  1977.     call    ctlook        ;find starting entry
  1978.     jmp    clist
  1979. ;
  1980. clist0:    call    iecnt
  1981.     mov    bx,offset ctlbas ;start with first
  1982. clist:    call    keychk        ;test for user break
  1983.     mov    dx,1[bx] ;addr from table entry
  1984.     add    bx,3
  1985.     mov    al,dh
  1986.     and    al,dl
  1987.     inc    al
  1988.     jnz    clist2        ;not at table end
  1989.     call    crlf
  1990.     jmp    nodoct
  1991. ;
  1992. clist2:    mov    al,-3[bx]
  1993.     cmp    al,segsho
  1994.     jnz    skclis        ;ignore this one
  1995.     push    dx
  1996.     push    bx
  1997.     call    symluk        ;symbol at this address?
  1998.     jb    l0e99        ;no
  1999.     call    iecnt        ;bump line count
  2000.     call    crlf        ;and fresh start
  2001. l0e87:    mov    al,[bx]        ;ctl mode char
  2002.     call    typech        ;put out symb char
  2003.     inc    bx
  2004.     dec    ch        ;till done
  2005.     jnz    l0e87
  2006.     mov    al,':'        ;delimit it
  2007.     call    typech
  2008.     call    crlf
  2009. l0e99:    pop    bx
  2010.     pop    dx
  2011.     call    prspc
  2012.     call    prspc
  2013.     xchg    bx,dx
  2014.     call    prword        ;output ctl tbl value
  2015.     mov    al,'='    ;2ch
  2016.     call    typech        ;delimiter
  2017.     mov    al,' '
  2018.     call    typech        ;and space
  2019.     xchg    bx,dx
  2020.     mov    al,[bx]
  2021.     call    typech        ;char from table
  2022.     call    prspc
  2023.     call    prspc
  2024.     call    spcrlf
  2025. skclis:    inc    bx
  2026.     jmp    clist
  2027. ;
  2028. savctl:    call    svctl0
  2029.     jmp    nxcmd
  2030. ;
  2031. svctl0:    call    creatf        ;make a new file
  2032.     mov    bx,offset ctlbas ;table start
  2033. l0ebf:    mov    dx,1[bx]    ;address value
  2034.     mov    al,dh
  2035.     and    al,dl
  2036.     inc    al
  2037.     jz    l0ee6        ;if table end flag ffff
  2038.     mov    al,[bx]        ;seg char
  2039.     call    wtfchr
  2040.     call    outadr
  2041.     mov    al,','    ;2ch
  2042.     call    wtfchr
  2043.     mov    al,3[bx]
  2044.     call    wtfchr
  2045.     mov    al,cr
  2046.     call    wtfchr
  2047.     mov    al,lf
  2048.     call    wtfchr
  2049.     add    bx,4
  2050.     jmp    l0ebf
  2051. ;
  2052. l0ee6:    mov    al,1ah
  2053.     call    wtfchr
  2054.     call    flushf
  2055.     jmp    nxcmd
  2056. ;
  2057. lodctl:    call    fopen
  2058.     jnb    ctlfnd        ;have one
  2059.     ret
  2060. ctlfnd:    mov    bx,offset ctlbas
  2061. l0ef7:    call    rdfchr
  2062.     cmp    al,1ah
  2063.     jz    l0f30        ;if eof
  2064.     cmp    al,' '+1
  2065.     jb    l0ef7        ;eat space and ctrl chars
  2066.     mov    [bx],al        ;segment char
  2067.     call    rdfchr
  2068.     mov    dx,0        ;clear addr accum
  2069. l0efd:    cmp    al,1ah
  2070.     jz    l0f30        ;if eof
  2071.     cmp    al,','    ;2ch
  2072.     jz    l0f23        ;if delim
  2073.     cmp    al,'9'+1
  2074.     jb    l0f0b        ;if can be dec digit
  2075.     sub    al,7        ;alpha to hex
  2076. l0f0b:    sub    al,'0'    ;30h    ;to bin
  2077.     add    dx,dx
  2078.     add    dx,dx
  2079.     add    dx,dx
  2080.     add    dx,dx
  2081.     add    dl,al
  2082.     call    rdfchr        ;whats next
  2083.     jmp    l0efd
  2084. ;
  2085. l0f23:    mov    1[bx],dx
  2086.     call    rdfchr
  2087.     mov    3[bx],al
  2088.     add    bx,4
  2089.     jmp    l0ef7
  2090. ;
  2091. l0f30:    mov    word ptr 1[bx],0ffffh
  2092.     add    bx,4
  2093.     call    fclose
  2094.     ret
  2095. ;
  2096. ;
  2097. ;
  2098. ;    comment table structure, variable lgth records
  2099. ;    2 byte address, 1 byte string count, n byte string
  2100. ;    table terminated by 0ffffh in address field
  2101. ;    no table exists if doctbl = 0
  2102. ;    if char 1 = ; comment appended to instruction
  2103. ;    if char 1 = * comment replaces instruction
  2104. ;    else comment on separate line before instruction
  2105. ;
  2106. cmcmnt:    call    l1041
  2107.     call    sgreqs
  2108.     mov    bx,offset cmdbuf+3
  2109.     mov    al,byte ptr [bx]
  2110.     cmp    al,cr
  2111.     jnz    cmnt0
  2112.     jmp    l0fd4
  2113. ;
  2114. cmnt0:    cmp    al,'0'
  2115.     jnz    cmnt1
  2116.     inc    bx
  2117.     mov    al,[bx]
  2118.     sub    al,'F'
  2119.     jz    cmnt2
  2120.     cmp    al,'N'-'F'
  2121.     jz    cmnt2
  2122.     call    cmerr
  2123. ;
  2124. cmnt2:    mov    xcsw,al
  2125.     jmp    nxcmd
  2126. ;
  2127. cmnt1:    call    gtval
  2128.     inc    bx
  2129.     cmp    al,cr
  2130.     jnz    l0f52
  2131.     jmp    l0fce
  2132. ;
  2133. l0f52:    call    delim
  2134. l0f5d:    push    bx
  2135.     call    comchk
  2136.     jb    l0f71
  2137.     call    l100b
  2138.     pop    bx
  2139.     push    bx
  2140.     mov    al,[bx]
  2141.     cmp    al,cr
  2142.     jnz    l0f71
  2143.     jmp    nxcmd
  2144. ;
  2145. l0f71:    mov    bx,docend
  2146.     mov    [bx],dx
  2147.     inc    bx
  2148.     inc    bx
  2149.     pop    dx
  2150.     mov    ch,0
  2151.     push    bx
  2152. l0f7d:    inc    bx
  2153.     xchg    bx,dx
  2154.     mov    al,[bx]
  2155.     xchg    bx,dx
  2156.     mov    [bx],al
  2157.     inc    dx
  2158.     inc    ch
  2159.     xchg    bx,dx
  2160.     mov    al,[bx]
  2161.     xchg    bx,dx
  2162.     cmp    al,cr
  2163.     jnz    l0f7d
  2164.     inc    bx
  2165.     mov    docend,bx
  2166.     mov    word ptr [bx],0ffffh
  2167.     pop    bx
  2168.     mov    [bx],ch
  2169.     jmp    nxcmd
  2170. ;
  2171. comchk:    mov    bx,doctbl
  2172. l0fa6:    mov    al,[bx]
  2173.     inc    bx
  2174.     and    al,[bx]
  2175.     dec    bx
  2176.     inc    al
  2177.     stc
  2178.     jnz    l0fb2
  2179.     ret
  2180. ;
  2181. l0fb2:    inc    bx
  2182.     mov    al,dh
  2183.     cmp    al,[bx]
  2184.     pushf
  2185.     dec    bx
  2186.     popf
  2187.     jnz    l0fc3
  2188.     mov    al,dl
  2189.     cmp    al,[bx]
  2190.     jnz    l0fc3
  2191.     ret
  2192. ;
  2193. l0fc3:    inc    bx
  2194.     inc    bx
  2195.     mov    al,[bx]
  2196.     call    addfn
  2197.     inc    bx
  2198.     jmp    l0fa6
  2199. ;
  2200. l0fce:    call    comchk
  2201.     jmp    l0fd8
  2202. ;
  2203. l0fd4:    mov    bx,doctbl
  2204. l0fd8:    call    keychk
  2205.     mov    dl,[bx]
  2206.     inc    bx
  2207.     mov    dh,[bx]
  2208.     inc    bx
  2209.     mov    al,dh
  2210.     and    al,dl
  2211.     inc    al
  2212.     jnz    l0fec
  2213.     jmp    nxcmd
  2214. ;
  2215. l0fec:    xchg    bx,dx
  2216.     call    prword
  2217.     xchg    bx,dx
  2218.     mov    al,';'    ;3bh
  2219.     call    typech
  2220.     mov    ch,[bx]
  2221. l0ffa:    inc    bx
  2222.     mov    al,[bx]
  2223.     call    typech
  2224.     dec    ch
  2225.     jnz    l0ffa
  2226.     call    crlf
  2227.     inc    bx
  2228.     jmp    l0fd8
  2229. ;
  2230. l100b:    mov    al,[bx]
  2231.     inc    bx
  2232.     and    al,[bx]
  2233.     inc    al
  2234.     jnz    l1015
  2235.     ret
  2236. ;
  2237. l1015:    dec    bx
  2238.     push    dx
  2239.     mov    dx,bx
  2240.     inc    bx
  2241.     inc    bx
  2242.     mov    al,[bx]
  2243.     call    addfn
  2244.     inc    bx
  2245.     mov    ch,0
  2246. l1023:    mov    al,[bx]
  2247.     xchg    bx,dx
  2248.     mov    [bx],al
  2249.     xchg    bx,dx
  2250.     inc    bx
  2251.     inc    dx
  2252.     mov    cl,al
  2253.     and    al,ch
  2254.     inc    al
  2255.     mov    ch,cl
  2256.     jnz    l1023
  2257.     xchg    bx,dx
  2258.     dec    bx
  2259.     dec    bx
  2260.     mov    docend,bx
  2261.     pop    dx
  2262.     ret
  2263. ;
  2264. l1041:    mov    bx,doctbl
  2265.     mov    al,bh
  2266.     or    al,bl
  2267.     jz    l104c
  2268.     ret
  2269. ;
  2270. l104c:    call    prtstr
  2271.     db    '++COMMAND IGNORED++',cr,lf
  2272.     db    '++ISSUE ','UNNNN',' TO TELL '
  2273.     db    'RESOURCE TO USE ADDRESS NNNN',cr,lf
  2274.     db    'AS THE START OF THE COMMENTS TABLE',cr,lf,0
  2275.     jmp    nxcmd
  2276. ;
  2277. ;
  2278. ;
  2279. cmusec:    mov    bx,offset cmdbuf+3
  2280.     mov    al,[bx]
  2281.     cmp    al,cr
  2282.     jnz    l10ce
  2283.     call    cmerr
  2284. ;
  2285. l10ce:    cmp    al,'.'    ;2eh
  2286.     jnz    ustok
  2287.     call    cmerr
  2288. ;
  2289. ustok:    call    gtval
  2290.     push    dx
  2291.     mov    bx,hiload
  2292.     mov    dx,curofs
  2293.     add    bx,dx
  2294.     inc    bh
  2295.     mov    dx,bx
  2296.     pop    bx
  2297.     cmp    bx,dx
  2298.     jb    l10ef
  2299.     call    uaset
  2300.     jmp    nxcmd
  2301. ;
  2302. uaset:    mov    doctbl,bx
  2303.     mov    docend,bx
  2304.     mov    word ptr [bx],0ffffh
  2305.     jmp    nxcmd
  2306. ;
  2307. l10ef:    call    prtstr
  2308.     db    '++NO!! <=',0
  2309.     mov    bx,offset symbas
  2310.     call    prword
  2311.     call    prtstr
  2312.     db    '!',cr,lf,0
  2313.     jmp    nxcmd
  2314. ;
  2315. hsym:    push    dx
  2316.     push    bx
  2317.     mov    wfiflg,1
  2318.     mov    bx,pcntr
  2319.     xchg    bx,dx
  2320.     call    symluk
  2321.     jb    l1152        ;no symbol/label here
  2322.     mov    cl,ch
  2323.     push    bx
  2324. l111c:    mov    al,[bx]
  2325.     cmp    al,'+'    ;2bh
  2326.     jz    l1151
  2327.     cmp    al,'-'    ;2dh
  2328.     jz    l1151
  2329.     inc    bx
  2330.     dec    cl
  2331.     jnz    l111c
  2332.     pop    bx
  2333.     call    pstrg
  2334.     mov    al,symtyp
  2335.     and    al,0fh
  2336.     cmp    al,0ch
  2337.     jnz    l1152 
  2338.     mov    al,':'    ;3ah
  2339.     call    typech
  2340.     mov    al,trmflg
  2341.     or    al,al
  2342.     jnz    l1152
  2343.     call    tabc
  2344.     call    tabc
  2345.     call    semic
  2346.     mov    bx,pcntr
  2347.     call    prword
  2348.     call    crlf
  2349.     jmp    l1152
  2350. ;
  2351. l1151:    pop    bx
  2352. l1152:    mov    wfiflg,0
  2353.     call    prspc
  2354.     call    prspc
  2355.     mov    bx,pcntr
  2356.     call    prword
  2357.     mov    wfiflg,1
  2358.     call    tabc
  2359.     pop    bx
  2360.     pop    dx
  2361.     ret
  2362. ;
  2363.  
  2364. code    ends
  2365.     end
  2366.  
  2367.